<template>
  <!-- 意见弹框 -->
  <el-dialog
    title="批量生成"
    :visible.sync="visible"
    :close-on-click-modal="false"
    width="90%"
    append-to-body
    v-dialogDrag="true"
  >
    <el-form class="handleform" :model="queryParams" size="small" label-width="80px">
    	<el-row type="flex">
    		<el-col :span="4">
    			<el-form-item label="单位名称" prop="entrustOrganizationId" >
            <entrustSelect :eid.sync="queryParams.entrustOrganizationId" @change="upEid" :name="queryParams.organizationName"></entrustSelect>
        	</el-form-item>
    		</el-col>
        <el-col :span="4">
    			<el-form-item label="年份" prop="year">
    			  <el-date-picker
              v-model="queryParams.year"
              type="year"
              :clearable="false"
              style="width: 100%;"
              value-format="yyyy"
              placeholder="选择年"
              @change="handleChangeYear"
            >
    			  </el-date-picker>
    			</el-form-item>
    		</el-col>
        <el-col :span="2">
          <el-form-item label-width="0" style="margin-left: 16px;">
            <el-button type="primary"  size="mini" @click.native.prevent="getList">搜索</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row type="flex">
      <el-col :span="3">
        <el-button type="primary" :disabled="multiple" size="mini" @click.native.prevent="handleGenerate">生成</el-button>
      </el-col>
    </el-row>
    <el-table class="handletabel"
      ref="tableData"
      v-loading="loading"
      :data="dataList"
      height="364"
      @selection-change="handleSelectionChange"
      @row-dblclick="openhandleDialog($event, 'view')"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="报告编号" align="center" prop="reportNumber" /> -->
      <el-table-column label="单位名称" align="center" prop="organizationName" show-overflow-tooltip/>
      <!-- <el-table-column label="单位地址" align="center" prop="organizationAddress" show-overflow-tooltip/> -->
      <el-table-column label="年份" align="center" prop="year" />
      <el-table-column label="第一批次监测日期" align="center">
        <template slot-scope="{ row }">
          {{ parseTime(row.beginTime1, '{y}-{m}-{d}') + ' - ' + parseTime(row.endTime1, '{y}-{m}-{d}')}}
        </template>
      </el-table-column>
      <el-table-column label="第二批次监测日期" align="center" prop="beginTime2" >
        <template slot-scope="{ row }">
          {{ parseTime(row.beginTime2, '{y}-{m}-{d}') + ' - ' + parseTime(row.endTime2, '{y}-{m}-{d}')}}
        </template>
      </el-table-column>
      <el-table-column label="第三批次监测日期" align="center" prop="beginTime3" >
        <template slot-scope="{ row }">
          {{ parseTime(row.beginTime3, '{y}-{m}-{d}') + ' - ' + parseTime(row.endTime3, '{y}-{m}-{d}')}}
        </template>
      </el-table-column>
      <el-table-column label="第四批次监测开始日期" align="center" prop="beginTime4" >
        <template slot-scope="{ row }">
          {{ parseTime(row.beginTime4, '{y}-{m}-{d}') + ' - ' + parseTime(row.endTime4, '{y}-{m}-{d}')}}
        </template>
      </el-table-column>
      <!-- <el-table-column label="仪器名称" align="center" prop="equipmentName" show-overflow-tooltip/>
      <el-table-column label="仪器型号" align="center" prop="equipmentTypeNumber" />
      <el-table-column label="仪器编号" align="center" prop="equipmentNumber" />
      <el-table-column label="探测器" align="center" prop="detector" show-overflow-tooltip/> -->
    </el-table>

    <el-dialog
      title="查看详情"
      :visible.sync="detailvisible"
      :close-on-click-modal="false"
      width="60%"
      append-to-body
      v-dialogDrag="true"
    >
      <el-table 
        class="handletabel"
        ref="tableData"
        v-loading="loading"
        :data="detailLists"
        height="364"
        :cell-class-name="tableCellClassName"
      >
      <el-table-column label="剂量计编号" align="center" prop="dosageNumber" />
      <el-table-column label="姓名" align="center" prop="personnelName" />
      <el-table-column label="性别" align="center" prop="personnelSex" >
        <template slot-scope="scope">
          <dict-tag :value="scope.row.personnelSex" :options = "dict.type.sys_user_sex">
          </dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="职业类别" align="center" prop="occupationalClassificationName" >
        <template slot-scope="scope">
          {{scope.row.occupationalClassificationName}}
        </template>
      </el-table-column>
      <el-table-column label="监测周期" align="center">
        <el-table-column label="第一批次(mSv)" align="center" prop="value1" >
          <template slot-scope="{ row }">
            <span>{{ row.value1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="第二批次(mSv)" align="center" prop="value2" >
          <template slot-scope="{ row }">
            <span>{{ row.value2 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="第三批次(mSv)" align="center" prop="value3" >
          <template slot-scope="{ row }">
            <span>{{ row.value3 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="第四批次(mSv)" align="center" prop="value4" >
          <template slot-scope="{ row }">
            <span>{{ row.value4 }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="剂量当量总和" align="center" prop="dosageValue" >
        <template slot="header">
          <div>剂量当量 Hp(10)</div>
        </template>
      </el-table-column>
      </el-table>
    </el-dialog>
  </el-dialog>
</template>

<script>
import { getAnnualDoseInfoList, annualAddBatch } from "@/api/slides/annualdose"
  import entrustSelect from '@/components/select/src/entrustSelect'
export default {
  name: 'GenerateDialog',
  components: {
    entrustSelect
  },
  dicts: ['sys_user_sex'],
  data() {
    return {
      visible: false,
      detailvisible: false,
      loading: false,
      dataList: [],
      detailLists: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        year: '2024'
      },
      selection: [],
      multiple: true
    }
  },
  methods: {
    async open() {
      await this.getList()
      this.visible = true
    },
    upEid(val){
      this.queryParams.entrustOrganizationId = val.entrustOrganizationId
      this.queryParams.organizationName = val.organizationName
    },
    handleChangeYear(val) {
      console.log(val);
      this.getList()
    },
    /** 多选框选中数据 */
    handleSelectionChange(selection) {
      this.selection = selection
      this.multiple = !selection.length
    },
    async getList() {
      this.loading = true
      let {code, data, msg} = await getAnnualDoseInfoList(this.queryParams)
      code == 200 && (this.dataList = (data || []))
      this.loading = false
    },
    openhandleDialog(row) {
      this.detailLists = row.taskAnnualDoseInfoRecordList
      this.detailvisible = true
      // console.log(this.$parent.openhandleDialog(, 'view'));
    },
    // 给单元格绑定横向和竖向的index，这样就能确定是哪一个单元格
    tableCellClassName({row, column, rowIndex, columnIndex}){
      row.index = rowIndex;
      column.index = columnIndex;
    },
    handleGenerate() {
      console.log(this.selection);
      annualAddBatch(this.selection).then(res => {
        this.$message.success('生成成功')
        this.getList()
      })
    }
  },
}
</script>

<style>

</style>
